import Base from './base.js';
import underscore from 'underscore';
let userList = {};
export default class extends Base {
      async openAction() {
            // this.websocket.join()            
            this.emit('join', 'This client opened successfully!')
      }
      closeAction(){           
            // console.log(this.wsData);
            
            // console.log(this.websocket.clients().sockets);
             
            // console.log(22);
      }
      roomAction(){
            console.log(11);      
      }
      addUserAction(){
            // clientsCount
            // console.log(this.websocket.sockets.server.eio.clients);
            // console.log(this.websocket.sockets);
            // console.log(this.websocket.clients().sockets)

            
            // console.log('获取客户端 addUser 事件发送的数据', this.wsData);
            // const toSocket = underscore.findWhere(this.socketClients,{id:this.wsData.id});
            // console.log(toSocket);
            
            // console.log(this.websocket.clients().sockets[key]);
            
            
            // toSocket['emit']('joined','asdasd');
            
            // this.emit('joined', `返回数据${this.wsData.name}`);
      }
      joinAction(){
            const {roomId,id} = this.wsData;
            
            if(!userList[roomId]){
                  userList[roomId] = [id]
            }
            else{
                  const newUser = userList[roomId].filter((item:string)=>{
                        return item===id;
                  })                               
                  if(!newUser.length) 
                        userList[roomId].push(id)
            }
            console.log(userList);
            this.emit('joined', `现有用户${userList[roomId].length}`);
      }
}



